import sqlite3
import pandas as pd
conn = sqlite3.connect('test.db')
cur = conn.cursor()
import sqlalchemy

data = pd.read_csv("djy.csv")
'''
sql = "CREATE TABLE COMPNAY(ID integer PRIMARY KEY autoincrement," \
        "EQUIPMENTNAME VARCHAR (20)," \
        "CATEGORY VARCHAR (20)," \
        "AREA VARCHAR (20)," \
        "RTDGROUP VARCHAR (20)," \
        "BATCHLOTCNT VARCHAR (20)," \
        "BATCHWAFERCNT VARCHAR (20)," \
        "AMR_FLAG VARCHAR (20)," \
        "TYPE1 VARCHAR (20)," \
        "FIXED VARCHAR (20)," \
        "TMPCOUNT VARCHAR (20)," \
        "THRESHOLD VARCHAR (20)," \
        "QT1 VARCHAR (20)," \   
        "QT2 VARCHAR (20)," \
        "AREA1 VARCHAR (20)," \
        "FIXCOUNTUPPERLIMIT VARCHAR (20))"
cur.execute(sql)
'''

data.to_sql('djy', conn, if_exists='replace',index=False)
#dtype={'EQUIPMENTNAME':sqlalchemy.types.TEXT}
# 三个模式：fail，若表存在，则不输出；replace：若表存在，覆盖原来表里的数据；append：若表存在，将数据写到原表的后面。默认为fail
#index：是否将df的index单独写到一列中
#index_label:指定列作为df的index输出，此时index为True
#chunksize： 同read_sql
#dtype: 指定列的输出到数据库中的数据类型。字典形式储存：{column_name: sql_dtype}。
# 常见的数据类型有sqlalchemy.types.INTEGER(), sqlalchemy.types.NVARCHAR(),sqlalchemy.Datetime()等


cur.close()
conn.close()